package com.china08.yxyapi.api.manage.stu.mystudy.huixue.scoreimprove;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.huixue.YxyHuixuePlan;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.huixue.YxyHuixuePlanRepository;

import io.swagger.annotations.ApiOperation;

/**
 * 首页--成绩提升(查询当前学生正在进行中的学科list)
 * 
 */
@CrossOrigin
@RestController
public class YxyHuixuePlanSubjectListSrhController extends YxyApiBaseController {

    @Autowired
    private YxyHuixuePlanRepository yxyHuixuePlanRepository;

    @ApiOperation(value = "成绩提升  查询当前学生正在进行中的学科list")
    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/stu/mystudy/huixue/scoreimprove/subjectlist", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response,
            @RequestBody(required = false) RepModel reqModel) throws ParseException {
        List<YxyHuixuePlan> planlist = yxyHuixuePlanRepository.findByStudentIdAndStatus(reqModel.studentId, 1);
        Set<String> submap = new HashSet<>();
        if (planlist != null && planlist.size() > 0) {
            for (YxyHuixuePlan entity : planlist) {
                submap.add(entity.getSubject());
            }
        }
        RespModel respModel = new RespModel();
        List<String> subs = new ArrayList<>();
        subs.addAll(submap);
        respModel.subidList = subs;
        return respModel;
    }

    protected static class RepModel extends YxyApiReqModel {

        public String studentId;// 学生id

    }

    protected static class RespModel extends YxyApiRespModel {
        public List<String> subidList;// 返回该学生正在进行中的学科id的list集合
    }
}
